package com.richesup.common.oss.common;

/**
 * Created by 13120 on 2018-6-21.
 */
public class ResultEntity<T>{

    private String message;
    private String code;
    private T data;

    private ResultEntity(T data) {
        this.code = "200";
        this.message = "成功";
        this.data = data;
    }
    private ResultEntity(CodeMessage cm) {
        if(cm == null){
            return;
        }
        this.code = cm.getCode();
        this.message = cm.getMessage();
    }
    /**
     * 成功时候的调用
     * @return
     */
    public static <T> ResultEntity<T> success(T data){
        return new ResultEntity<T>(data);
    }
    /**
     * 成功，不需要传入参数
     * @return
     */
    @SuppressWarnings("unchecked")
    public static <T> ResultEntity<T> success(){
        return (ResultEntity<T>) success("");
    }
    /**
     * 失败时候的调用
     * @return
     */
    public static <T> ResultEntity<T> error(CodeMessage cm){
        return new ResultEntity<T>(cm);
    }
    /**
     * 失败时候的调用,扩展消息参数
     * @param cm
     * @param msg
     * @return
     */
    public static <T> ResultEntity<T> error(CodeMessage cm,String msg){
        cm.setMessage(cm.getMessage()+"--"+msg);
        return new ResultEntity<T>(cm);
    }
    public T getData() {
        return data;
    }
    public String getMessage() {
        return message;
    }
    public String getCode() {
        return code;
    }

}
